package o2o.config.dao.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * @Description: TODO
 * Created with IntelliJ IDEA.
 * User: Jahnke [1029777564@qq.com]
 * Date: 2019-04-20 12:03
 * To change this template use File | Settings | File Templates.
 */
@Configuration
public class DataSourceConfig {

    // 主数据源
    @Primary            // 一定要有一个主数据源，并且在上面加上@Primary
    @Bean(value = "cloudPrimarySource")
    @ConfigurationProperties(prefix = "c3p0.primary")
    @Qualifier("cloudPrimarySource")
    public DataSource userDbSource() {
        return DataSourceBuilder.create().type(com.mchange.v2.c3p0.ComboPooledDataSource.class).build();
    }

    // base系统数据源
    @Bean(value = "cloudSecondSource")
    @ConfigurationProperties(prefix = "c3p0.second")
    @Qualifier("cloudSecondSource")
    public DataSource dataDbSource() {
        return DataSourceBuilder.create().type(com.mchange.v2.c3p0.ComboPooledDataSource.class).build();
    }

}
